import React, {Component} from 'react';

class Child extends Component{
    state={
        title:'qwe'
    }
    render() {
        return(
            <div>child
            <span>{this.props.text}</span>
            <span>{this.state.title}</span>
            </div>
        )
    }
    componentWillReceiveProps(nextProps, nextContext) {
        console.log(nextProps)
        console.log(nextContext)
        //最先获得父组件传来的属性,可以利用属性进行ajxa或者逻辑处理
        //把属性转化成孩子自己的状态
        this.setState({
            title:nextProps.text+'阿达是的'
        })
    }
}

class App extends Component {
    state={
        text:'111111'
    }
    render() {
        return (
            <div>
                {
                    this.state.text
                }
                <button onClick={()=>{
                    this.setState({
                        text:'hhhhhh'
                    })
                }}>click</button>
                <Child text={this.state.text}></Child>
            </div>
        );
    }
}

export default App;